package com.ccp.dev.workflow.model;



import com.ccp.dev.core.util.StringUtil;
import com.ccp.dev.workflow.model.BpmDefAuthorizeType.BPMDEFAUTHORIZE_RIGHT_TYPE;
import net.sf.json.JSONObject;

/**
 * 对象功能:流程授权
 * 开发人员:xucx
 * 创建时间:2014-03-05 09:00:53
 */

public class AuthorizeRight 
{
	
	/*
	 *  //流程授权启动类型
	 *	public static final String START="start";
	 *	//流程授权管理类型
	 *	public static final String MANAGEMENT="management";
	 * 
	 *  管理类型的权限
	 *  "rightContent":{"m_edit":"Y","m_del":"N","m_start":"Y","m_set":"N"}
	 * */
	/**
	 * 流程授权权限_管理_设计
	 */
	private static final String BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_EDIT = "m_edit";

	/**
	 * 流程授权权限_管理_启动
	 */
	private static final String BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_START = "m_start";

	/**
	 * 流程授权权限_管理_设置
	 */
	private static final String BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_SET = "m_set";

	/**
	 * 流程授权权限_管理_删除
	 */
	private static final String BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_DEL = "m_del";

	/**
	 * 流程授权权限_管理_国际化
	 */
	private static final String BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_INTERNATIONAL = "m_international";

	/**
	 * 流程授权权限_管理_清除数据
	 */
	private static final String BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_CLEAN = "m_clean";

	/**
	 * 流程授权权限_实例_删除
	 */
	private static final String BPMDEFAUTHORIZE_RIGHT_INSTANCE_DEL = "i_del";

	/**
	 * 流程授权权限_实例_日志
	 */
	private static final String BPMDEFAUTHORIZE_RIGHT_INSTANCE_LOG = "i_log";

	/**
	 * 流程授权类型
	 */
	private String authorizeType = BPMDEFAUTHORIZE_RIGHT_TYPE.MANAGEMENT;

	/**
	 * 流程授权说明
	 */
	private String defKey;

	/**
	 * 管理类型流程授权编辑权限
	 */
	private String managementEdit = "N";

	/**
	 * 管理类型流程授权删除权限
	 */
	private String managementDel = "N";

	/**
	 * 管理类型流程授权启动流程权限
	 */
	private String managementStart = "N";

	/**
	 * 管理类型流程授权设置权限
	 */
	private String managementSet = "N";

	/**
	 * 管理类型流程授权国际化权限
	 */
	private String managementInternational = "N";

	/**
	 * 管理类型流程授权清除数据权限
	 */
	private String managementClean = "N";

	/**
	 * 实例类型流程授权删除流程实例权限
	 */
	private String instanceDel = "N";

	/**
	 * 实例类型流程授权管理流程实例日志权限
	 */
	private String instanceLog = "N";

	/**
	 * 流程授权JSON字符串
	 */
	private String rightContent = "";

	/**
	 * 流程授权JSON对象
	 */
	private JSONObject rightJsonObj = new JSONObject();
	

	public String getAuthorizeType() {
		return authorizeType;
	}

	public void setAuthorizeType(String authorizeType) {
		this.authorizeType = authorizeType;
	}

	public String getDefKey() {
		return defKey;
	}

	public void setDefKey(String defKey) {
		this.defKey = defKey;
	}

	public String getManagementEdit() {
		return managementEdit;
	}

	public void setManagementEdit(String managementEdit) {
		this.managementEdit = managementEdit;
	}

	public String getManagementDel() {
		return managementDel;
	}

	public void setManagementDel(String managementDel) {
		this.managementDel = managementDel;
	}

	public String getManagementStart() {
		return managementStart;
	}

	public void setManagementStart(String managementStart) {
		this.managementStart = managementStart;
	}

	public String getManagementSet() {
		return managementSet;
	}

	public void setManagementSet(String managementSet) {
		this.managementSet = managementSet;
	}

	public String getManagementInternational() {
		return managementInternational;
	}

	public void setManagementInternational(String managementInternational) {
		this.managementInternational = managementInternational;
	}

	public String getManagementClean() {
		return managementClean;
	}
	
	public void setManagementClean(String managementClean) {
		this.managementClean = managementClean;
	}

	public String getInstanceDel() {
		return instanceDel;
	}

	public void setInstanceDel(String instanceDel) {
		this.instanceDel = instanceDel;
	}

	public String getInstanceLog() {
		return instanceLog;
	}

	public void setInstanceLog(String instanceLog) {
		this.instanceLog = instanceLog;
	}

	public String getRightContent() {
		return rightContent;
	}

	public void setRightContent(String rightContent) {
		this.rightContent = rightContent;
		if(StringUtil.isNotEmpty(rightContent)){
			JSONObject obj = JSONObject.fromObject(rightContent);
			//流程定义类型的管理权限
			if(BPMDEFAUTHORIZE_RIGHT_TYPE.MANAGEMENT.equals(this.authorizeType)){
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_EDIT)){
	            	this.managementEdit = obj.getString(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_EDIT);
	            }
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_DEL)){
		            this.managementDel = obj.getString(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_DEL);
		        }
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_START)){
		            this.managementStart = obj.getString(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_START);
		        }
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_SET)){
					this.managementSet = obj.getString(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_SET);
		        }
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_INTERNATIONAL)){
					this.managementInternational = obj.getString(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_INTERNATIONAL);
		        }
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_CLEAN)){
					this.managementClean = obj.getString(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_CLEAN);
		        }
			//流程实例管理类型的管理权限
			}else if(BPMDEFAUTHORIZE_RIGHT_TYPE.INSTANCE.equals(this.authorizeType)){
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_INSTANCE_DEL)){
		            this.instanceDel = obj.getString(BPMDEFAUTHORIZE_RIGHT_INSTANCE_DEL);
		        }
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_INSTANCE_LOG)){
		            this.instanceLog = obj.getString(BPMDEFAUTHORIZE_RIGHT_INSTANCE_LOG);
		        }
			}
			this.rightJsonObj = obj;
		}

	}

	/**
	 * 权限有更新时，为自己需要的权限就设置
	 * @param needRight
	 * @param rightContent
	 * @param authorizeType
	 */
	public void setRightByNeed(String needRight,String rightContent,String authorizeType) {
		if(StringUtil.isNotEmpty(needRight)&& StringUtil.isNotEmpty(rightContent)){
			JSONObject obj = JSONObject.fromObject(rightContent);
			//流程定义类型的管理权限
			if(BPMDEFAUTHORIZE_RIGHT_TYPE.MANAGEMENT.equals(authorizeType)){
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_EDIT)){
					String m_edit = obj.getString(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_EDIT);
					if(needRight.equals(m_edit)){
						this.managementEdit = m_edit;
						this.rightJsonObj.put(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_EDIT, m_edit);
					}
	            }
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_DEL)){
					String m_del = obj.getString(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_DEL);
					if(needRight.equals(m_del)){
						this.managementDel = m_del;
						this.rightJsonObj.put(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_DEL, m_del);
					}
		        }
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_START)){
		            String m_start = obj.getString(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_START);
					if(needRight.equals(m_start)){
						this.managementStart = m_start;
						this.rightJsonObj.put(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_START, m_start);
					}
		        }
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_SET)){
					String m_set = obj.getString(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_SET);
					if(needRight.equals(m_set)){
						this.managementSet = m_set;
						this.rightJsonObj.put(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_SET, m_set);
					}
		        }
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_INTERNATIONAL)){
					String m_international = obj.getString(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_INTERNATIONAL);
					if(needRight.equals(m_international)){
						this.managementInternational = m_international;
						this.rightJsonObj.put(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_INTERNATIONAL, m_international);
					}
		        }
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_CLEAN)){
					String m_clean = obj.getString(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_CLEAN);
					if(needRight.equals(m_clean)){
						this.managementClean = m_clean;
						this.rightJsonObj.put(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_CLEAN, m_clean);
					}
		        }
			//流程实例管理类型的管理权限
			}else if(BPMDEFAUTHORIZE_RIGHT_TYPE.INSTANCE.equals(authorizeType)){
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_INSTANCE_DEL)){
					String i_del = obj.getString(BPMDEFAUTHORIZE_RIGHT_INSTANCE_DEL);
					if(needRight.equals(i_del)){
						this.instanceDel = i_del;
						this.rightJsonObj.put(BPMDEFAUTHORIZE_RIGHT_INSTANCE_DEL, i_del);
					}
		        }
				if(obj.containsKey(BPMDEFAUTHORIZE_RIGHT_INSTANCE_DEL)){
		            String i_log = obj.getString(BPMDEFAUTHORIZE_RIGHT_INSTANCE_DEL);
					if(needRight.equals(i_log)){
						this.instanceLog = i_log;
						this.rightJsonObj.put(BPMDEFAUTHORIZE_RIGHT_INSTANCE_DEL, i_log);
					}
		        }
			}
			this.rightContent = this.rightJsonObj.toString();
		}

	}
	
	public void setRightByAuthorizeType(String right,String authorizeType) {
		this.authorizeType = authorizeType;
		//流程定义类型的管理权限
		if(BPMDEFAUTHORIZE_RIGHT_TYPE.MANAGEMENT.equals(authorizeType)){
			this.managementEdit = right;
			this.rightJsonObj.put(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_EDIT, right);
			this.managementDel = right;
			this.rightJsonObj.put(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_DEL, right);
			this.managementStart = right;
			this.rightJsonObj.put(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_START, right);
			this.managementSet = right;
			this.rightJsonObj.put(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_SET, right);
			this.managementInternational = right;
			this.rightJsonObj.put(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_INTERNATIONAL, right);
			this.managementClean = right;
			this.rightJsonObj.put(BPMDEFAUTHORIZE_RIGHT_MANAGEMENT_CLEAN, right);
		//流程实例管理类型的管理权限
		}else if(BPMDEFAUTHORIZE_RIGHT_TYPE.INSTANCE.equals(authorizeType)){
			this.instanceDel = right;
			this.instanceLog = right;
		}
		this.rightContent = this.rightJsonObj.toString();
	}

	public JSONObject getRightJsonObj() {
		return rightJsonObj;
	}

	public void setRightJsonObj(JSONObject rightJsonObj) {
		this.rightJsonObj = rightJsonObj;
	}

}